package com.share.common.enums;

import lombok.Getter;

import java.util.Optional;

@Getter
public enum DbTypeEnum {
    MYSQL("mysql", "mysql数据库"),
    HIVE("hive", "hive操作hdfs"),
    PHOENIX("phoenix", "phoenix连接hbase");

    //数据库
    public String code;

    //名字
    public String name;


    private DbTypeEnum(final String code, final String name) {
        this.code = code;
        this.name = name;
    }

    public static DbTypeEnum toEnum(final String code) {
        for (final DbTypeEnum tag : DbTypeEnum.values()) {
            if (tag.code.equals(code)) {
                return tag;
            }
        }
        return null;
    }

    public static String toName(final String code) {
        return Optional.ofNullable(toEnum(code)).map(item -> item.name).orElse(null);
    }
}
